Richard M. Stallman
Last updated 14 June 1995
for version 2.7
Copyright © 1988, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
For GCC Version 2.7.
Published by the Free Software Foundation
675 Massachusetts Avenue
Cambridge, MA 02139 USA
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the sections entitled “GNU General Public License,” “Funding for Free Software,” and “Protect Your Freedom—Fight ‘Look And Feel’” are included exactly as in the original, and provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that the sections entitled “GNU General Public License,” “Funding for Free Software,” and “Protect Your Freedom—Fight ‘Look And Feel’”, and this permission notice, may be included in translations approved by the Free Software Foundation instead of in the original English.
GNU GENERAL PUBLIC LICENSE | GNU General Public License says how you can copy and share GNU CC. | |
Contributors to GNU CC | People who have contributed to GNU CC. | |
1 Funding Free Software | How to help assure funding for free software. | |
2 Protect Your Freedom—Fight “Look And Feel” | Protect your freedom—fight “look and feel”. | |
3 Compile C, C++, or Objective C | You can compile C or C++ programs. | |
• Invoking GCC | Command options supported by ‘gcc’. | |
• Installation | How to configure, compile and install GNU CC. | |
• C Extensions | GNU extensions to the C language family. | |
• C++ Extensions | GNU extensions to the C++ language. | |
4 Known Causes of Trouble with GNU CC | If you have trouble installing GNU CC. | |
5 Reporting Bugs | How, why and where to report bugs. | |
6 How To Get Help with GNU CC | How to find suppliers of support for GNU CC. | |
7 Using GNU CC on VMS | ||
8 GNU CC and Portability | Goals of GNU CC’s portability features. | |
9 Interfacing to GNU CC Output | Function-call interface of GNU CC output. | |
10 Passes and Files of the Compiler | Order of passes, what they do, and what each file is for. | |
• RTL | The intermediate representation that most passes work on. | |
• Machine Desc | How to write machine description instruction patterns. | |
• Target Macros | How to write the machine description C macros. | |
11 The Configuration File | Writing the ‘xm-machine.h’ file. | |
Index | Index of concepts and symbol names. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Version 2, June 1991
Copyright © 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software—to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation’s software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author’s protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors’ reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone’s free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and “any later version”, you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
one line to give the program's name and a brief idea of what it does. Copyright (C) 19yy name of author This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands ‘show w’ and ‘show c’ should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than ‘show w’ and ‘show c’; they could even be mouse-clicks or menu items—whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a “copyright disclaimer” for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In addition to Richard Stallman, several people have written parts of GNU CC.
protoize
and unprotoize
tools, the support for Dwarf symbolic debugging information, and much of
the support for System V Release 4. He has also worked heavily on the
Intel 386 and 860 support.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you want to have more free software a few years from now, it makes sense for you to help encourage people to contribute funds for its development. The most effective approach known is to encourage commercial redistributors to donate.
Users of free software systems can boost the pace of development by encouraging for-a-fee distributors to donate part of their selling price to free software developers—the Free Software Foundation, and others.
The way to convince distributors to do this is to demand it and expect it from them. So when you compare distributors, judge them partly by how much they give to free software development. Show distributors they must compete to be the one who gives the most.
To make this approach work, you must insist on numbers that you can compare, such as, “We will donate ten dollars to the Frobnitz project for each disk sold.” Don’t be satisfied with a vague promise, such as “A portion of the profits are donated,” since it doesn’t give a basis for comparison.
Even a precise fraction “of the profits from this disk” is not very meaningful, since creative accounting and unrelated business decisions can greatly alter what fraction of the sales price counts as profit. If the price you pay is $50, ten percent of the profit is probably less than a dollar; it might be a few cents, or nothing at all.
Some redistributors do development work themselves. This is useful too; but to keep everyone honest, you need to inquire how much they do, and what kind. Some kinds of development make much more long-term difference than others. For example, maintaining a separate version of a program contributes very little; maintaining the standard version of a program for the whole community contributes much. Easy new ports contribute little, since someone else would surely do them; difficult ports such as adding a new CPU to the GNU C compiler contribute more; major new features or packages contribute the most.
By establishing the idea that supporting further development is “the proper thing to do” when distributing free software for a fee, we can assure a steady flow of resources into making more free software.
Copyright (C) 1994 Free Software Foundation, Inc. Verbatim copying and redistribution of this section is permitted without royalty; alteration is not permitted.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section is a political message from the League for Programming Freedom to the users of GNU CC. We have included it here because the issue of interface copyright is important to the GNU project.
Apple and Lotus have tried to create a new form of legal monopoly: a copyright on a user interface.
An interface is a kind of language—a set of conventions for communication between two entities, human or machine. Until a few years ago, the law seemed clear: interfaces were outside the domain of copyright, so programmers could program freely and implement whatever interface the users demanded. Imitating de-facto standard interfaces, sometimes with improvements, was standard practice in the computer field. These improvements, if accepted by the users, caught on and became the norm; in this way, much progress took place.
Computer users, and most software developers, were happy with this state of affairs. However, large companies such as Apple and Lotus would prefer a different system—one in which they can own interfaces and thereby rid themselves of all serious competitors. They hope that interface copyright will give them, in effect, monopolies on major classes of software.
Other large companies such as IBM and Digital also favor interface monopolies, for the same reason: if languages become property, they expect to own many de-facto standard languages. But Apple and Lotus are the ones who have actually sued. Lotus has won lawsuits against two small companies, which were thus put out of business. Then they sued Borland; this case is now before the court of appeals. Apple’s lawsuit against HP and Microsoft is also being decided by an appeals court. Widespread rumors that Apple had lost the case are untrue; as of July 1994, the final outcome is unknown.
If the monopolists get their way, they will hobble the software field:
If interface monopolies are accepted, other large companies are waiting to grab theirs:
Users invest a great deal of time and money in learning to use computer interfaces. Far more, in fact, than software developers invest in developing and even implementing the interfaces. Whoever can own an interface, has made its users into captives, and misappropriated their investment.
To protect our freedom from monopolies like these, a group of programmers and users have formed a grass-roots political organization, the League for Programming Freedom.
The purpose of the League is to oppose monopolistic practices such as interface copyright and software patents. The League calls for a return to the legal policies of the recent past, in which programmers could program freely. The League is not concerned with free software as an issue, and is not affiliated with the Free Software Foundation.
The League’s activities include publicizing the issue, as is being done here, and filing friend-of-the-court briefs on behalf of defendants sued by monopolists. Recently the League filed a friend-of-the-court brief for Borland in its appeal against Lotus.
The League’s membership rolls include John McCarthy, inventor of Lisp, Marvin Minsky, founder of the MIT Artificial Intelligence lab, Guy L. Steele, Jr., author of well-known books on Lisp and C, as well as Richard Stallman, the developer of GNU CC. Please join and add your name to the list. Membership dues in the League are $42 per year for programmers, managers and professionals; $10.50 for students; $21 for others.
Activist members are especially important, but members who have no time to give are also important. Surveys at major ACM conferences have indicated a vast majority of attendees agree with the League. If just ten percent of the programmers who agree with the League join the League, we will probably triumph.
To join, or for more information, phone (617) 243-4091 or write to:
League for Programming Freedom 1 Kendall Square #143 P.O. Box 9171 Cambridge, MA 02139
You can also send electronic mail to lpf@uunet.uu.net
.
In addition to joining the League, here are some suggestions from the League for other things you can do to protect your freedom to write programs:
House Subcommittee on Intellectual Property 2137 Rayburn Bldg Washington, DC 20515 Senate Subcommittee on Patents, Trademarks and Copyrights United States Senate Washington, DC 20510
(These committees have received lots of mail already; let’s give them even more.)
Democracy means nothing if you don’t use it. Stand up and be counted!
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The C, C++, and Objective C versions of the compiler are integrated; the GNU C compiler can compile programs written in C, C++, or Objective C.
“GCC” is a common shorthand term for the GNU C compiler. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs.
When referring to C++ compilation, it is usual to call the compiler “G++”. Since there is only one compiler, it is also accurate to call it “GCC” no matter what the language context; however, the term “G++” is more useful when the emphasis is on compiling C++ programs.
We use the name “GNU CC” to refer to the compilation system as a whole, and more specifically to the language-independent part of the compiler. For example, we refer to the optimization options as affecting the behavior of “GNU CC” or sometimes just “the compiler”.
Front ends for other languages, such as Ada 9X, Fortran, Modula-3, and Pascal, are under development. These front-ends, like that for C++, are built in subdirectories of GNU CC and link to it. The result is an integrated compiler that can compile programs written in C, C++, Objective C, or any of the languages for which you have installed front ends.
In this manual, we only discuss the options for the C, Objective-C, and C++ compilers and those of the GNU CC core. Consult the documentation of the other front ends for the options to use when compiling programs written in other languages.
G++ is a compiler, not merely a preprocessor. G++ builds object code directly from your C++ program source. There is no intermediate C version of the program. (By contrast, for example, some other implementations use a program that generates a C program from your C++ source.) Avoiding an intermediate C representation of the program means that you get better object code, and better debugging information. The GNU debugger, GDB, works with this information in the object code to give you comprehensive C++ source-level editing capabilities (see C and C++ in Debugging with GDB).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes known problems that affect users of GNU CC. Most of these are not GNU CC bugs per se—if they were, we would fix them. But the result for a user may be like the result of a bug.
Some of these problems are due to bugs in other software, some are missing features that are too much work to add, and some are places where people’s opinions differ as to what is best.
4.1 Actual Bugs We Haven’t Fixed Yet | Bugs we will fix later. | |
4.2 Installation Problems | Problems that manifest when you install GNU CC. | |
4.3 Cross-Compiler Problems | Common problems of cross compiling with GNU CC. | |
4.4 Interoperation | Problems using GNU CC with other compilers, and with certain linkers, assemblers and debuggers. | |
4.5 Problems Compiling Certain Programs | Problems compiling certain programs. | |
4.6 Incompatibilities of GNU CC | GNU CC is incompatible with traditional C. | |
4.7 Fixed Header Files | GNU C uses corrected versions of system header files. This is necessary, but doesn’t always work smoothly. | |
4.8 Standard Libraries | GNU C uses the system C library, which might not be compliant with the ISO/ANSI C standard. | |
4.9 Disappointments and Misunderstandings | Regrettable things we can’t change, but not quite bugs. | |
4.10 Common Misunderstandings with GNU C++ | Common misunderstandings with GNU C++. | |
4.11 Caveats of using protoize | Things to watch out for when using protoize .
| |
4.12 Certain Changes We Don’t Want to Make | Things we think are right, but some others disagree. | |
4.13 Warning Messages and Error Messages | Which problems in your code get warnings, and which get errors. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
fixincludes
script interacts badly with automounters; if the
directory of system header files is automounted, it tends to be
unmounted while fixincludes
is running. This would seem to be a
bug in the automounter. We don’t know any good way to work around it.
fixproto
script will sometimes add prototypes for the
sigsetjmp
and siglongjmp
functions that reference the
jmp_buf
type before that type is defined. To work around this,
edit the offending file and place the typedef in front of the
prototypes.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is a list of problems (and some apparent problems which don’t really mean anything is wrong) that show up during installation of GNU CC.
CC
can interfere with the functioning of make
.
fixincludes
if the
System V file system doesn’t support symbolic links. These problems
result in a failure to fix the declaration of size_t
in
‘sys/types.h’. If you find that size_t
is a signed type and
that type mismatches occur, this could be the cause.
The solution is not to use such a directory for building GNU CC.
gcc
driver program looked for
as
and ld
in various places; for example, in files
beginning with ‘/usr/local/lib/gcc-’. GNU CC version 2 looks for
them in the directory
‘/usr/local/lib/gcc-lib/target/version’.
Thus, to use a version of as
or ld
that is not the system
default, for example gas
or GNU ld
, you must put them in
that directory (or make links to them from that directory).
make
. These failures, which
are often due to files that were not found, are expected, and can safely
be ignored.
make
recompiles parts of the compiler when installing
the compiler. In one case, this was traced down to a bug in
make
. Either ignore the problem or switch to GNU Make.
enquire
, which is part of building
GNU CC. The fix is to get rid of the file real-ld
which purify
installs—so that GNU CC won’t try to use it.
__GNU_LIBRARY__
conditional
around line 31 to ‘#if 1’.
enquire
hangs due to a hardware problem in the motherboard—it
reports floating point exceptions to the kernel incorrectly. You can
install GNU CC except for ‘float.h’ by patching out the command to
run enquire
. You may also be able to fix the problem for real by
getting a replacement motherboard. This problem was observed in
Revision E of the Micronics motherboard, and is fixed in Revision F.
It has also been observed in the MYLEX MXA-33 motherboard.
If you encounter this problem, you may also want to consider removing the FPU from the socket during the compilation. Alternatively, if you are running SCO Unix, you can reboot and force the FPU to be ignored. To do this, type ‘hd(40)unix auto ignorefpu’.
One of these systems is the Unix from Interactive Systems: 386/ix. On this system, an alternate emulator is provided, and it does work. To use it, execute this command as super-user:
ln /etc/emulator.rel1 /etc/emulator
and then reboot the system. (The default emulator file remains present under the name ‘emulator.dflt’.)
Try using ‘/etc/emulator.att’, if you have such a problem on the SCO system.
Another system which has this problem is Esix. We don’t know whether it has an alternate emulator that works.
On NetBSD 0.8, a similar problem manifests itself as these error messages:
enquire.c: In function `fprop': enquire.c:2328: floating overflow
genflags
or genoutput
while building GNU CC. This is said to
be due to a bug in sh
. You can probably get around it by running
genflags
or genoutput
manually and then retrying the
make
.
The solution is to compile the current version of GNU CC without ‘-g’. That makes a working compiler which you can use to recompile with ‘-g’.
To check whether an optional package is installed, use
the pkginfo
command. To add an optional package, use the
pkgadd
command. For further details, see the Solaris
documentation.
For Solaris 2.0 and 2.1, GNU CC needs six packages: ‘SUNWarc’, ‘SUNWbtool’, ‘SUNWesu’, ‘SUNWhea’, ‘SUNWlibm’, and ‘SUNWtoo’.
For Solaris 2.2, GNU CC needs an additional seventh package: ‘SUNWsprot’.
PATH
.
add.d
.
It would be nice to extend GAS to produce the gp tables, but they are optional, and there should not be a warning about their absence.
fixincludes
. This causes
problems in building GNU CC. Once GNU CC is installed, the problems go
away.
To work around this problem, when making the stage 1 compiler, specify this option to Make:
GCC_FOR_TARGET="./xgcc -B./ -I./include"
When making stage 2 and stage 3, specify this option:
CFLAGS="-g -I./include"
Users have also reported some problems with version 2.20 of the MIPS compiler tools that were shipped with RISC/os 4.x. The earlier version 2.11 seems to work fine.
alloca
against shared
libraries on RISC-OS 5.0, and DEC’s OSF/1 systems. This is a bug
in the linker, that is supposed to be fixed in future revisions.
To protect against this, GNU CC passes ‘-non_shared’ to the
linker unless you pass an explicit ‘-shared’ or
‘-call_shared’ switch.
ld fatal: failed to write symbol name something in strings table for file whatever
This probably indicates that the disk is full or your ULIMIT won’t allow the file to be as large as it needs to be.
This problem can also result because the kernel parameter MAXUMEM
is too small. If so, you must regenerate the kernel and make the value
much larger. The default value is reported to be 1024; a value of 32768
is said to work. Smaller values may also work.
/usr/local/lib/bison.simple: In function `yyparse': /usr/local/lib/bison.simple:625: virtual memory exhausted
that too indicates a problem with disk space, ULIMIT, or MAXUMEM
.
To solve this problem, reconfigure the kernel adding the following line to the configuration file:
MAXUMEM = 4096
_floatdisf cc1: warning: `-g' option not supported on this version of GCC cc1: warning: `-g1' option not supported on this version of GCC ./xgcc: Internal compiler error: program as got fatal signal 11
A patched version of the assembler is available by anonymous ftp from
altdorf.ai.mit.edu
as the file
‘archive/cph/hpux-8.0-assembler’. If you have HP software support,
the patch can also be obtained directly from HP, as described in the
following note:
This is the patched assembler, to patch SR#1653-010439, where the assembler aborts on floating point constants.
The bug is not really in the assembler, but in the shared library version of the function “cvtnum(3c)”. The bug on “cvtnum(3c)” is SR#4701-078451. Anyway, the attached assembler uses the archive library version of “cvtnum(3c)” and thus does not exhibit the bug.
This patch is also known as PHCO_4484.
fixproto
shell script triggers a bug in the system shell.
If you encounter this problem, upgrade your operating system or
use BASH (the GNU shell) to run fixproto
.
muldi3
in file ‘libgcc2.c’.
You may be able to succeed by getting GNU CC version 1, installing it, and using it to compile GNU CC version 2. The bug in the Pyramid C compiler does not seem to affect GNU CC version 1.
va_arg
when you build GNU CC.
If this happens, then you need to link most programs with the library ‘iclib.a’. You must also modify ‘stdio.h’ as follows: before the lines
#if defined(__i860__) && !defined(_VA_LIST) #include <va_list.h>
insert the line
#if __PGC__
and after the lines
extern int vprintf(const char *, va_list ); extern int vsprintf(char *, const char *, va_list ); #endif
insert the line
#endif /* __PGC__ */
These problems don’t exist in operating system version 1.1.
./fixproto: sh internal 1K buffer overflow
To fix this, change the first line of the fixproto script to look like:
#!/bin/ksh
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You may run into problems with cross compilation on certain machines, for several reasons.
The compiler writes these integer constants by examining the floating point value as an integer and printing that integer, because this is simple to write and independent of the details of the floating point representation. But this does not work if the compiler is running on a different machine with an incompatible floating point format, or even a different byte-ordering.
In addition, correct constant folding of floating point values requires representing them in the target machine’s format. (The C standard does not quite require this, but in practice it is the only way to win.)
It is now possible to overcome these problems by defining macros such
as REAL_VALUE_TYPE
. But doing so is a substantial amount of
work for each target machine.
@xref{Cross-compilation}.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section lists various difficulties encountered in using GNU C or GNU C++ together with other compilers or with the assemblers, linkers, libraries and debuggers on certain systems.
This effect is intentional, to protect you from more subtle problems. Compilers differ as to many internal details of C++ implementation, including: how class instances are laid out, how multiple inheritance is implemented, and how virtual function calls are handled. If the name encoding were made the same, your programs would link against libraries provided from other compilers—but the programs would then crash when run. Incompatible libraries are then detected at link time, rather than at run time.
Many systems come with header files that won’t work with GNU CC unless
corrected by fixincludes
. The corrected header files go in a new
directory; GNU CC searches this directory before ‘/usr/include’.
If you use ‘-I/usr/include’, this tells GNU CC to search
‘/usr/include’ earlier on, before the corrected headers. The
result is that you get the uncorrected header files.
Instead, you should use these options (when compiling C programs):
-I/usr/local/lib/gcc-lib/target/version/include -I/usr/include
For C++ programs, GNU CC also uses a special directory that defines C++ interfaces to standard C subroutines. This directory is meant to be searched before other standard include directories, so that it takes precedence. If you are compiling C++ programs and specifying include directories explicitly, use this option first, then the two options above:
-I/usr/local/lib/g++-include
double
on an 8-byte
boundary, and it expects every double
to be so aligned. The Sun
compiler usually gives double
values 8-byte alignment, with one
exception: function arguments of type double
may not be aligned.
As a result, if a function compiled with Sun CC takes the address of an
argument of type double
and passes this pointer of type
double *
to a function compiled with GNU CC, dereferencing the
pointer may cause a fatal signal.
One way to solve this problem is to compile your entire program with GNU
CC. Another solution is to modify the function that is compiled with
Sun CC to copy the argument into a local variable; local variables
are always properly aligned. A third solution is to modify the function
that uses the pointer to dereference it via the following function
access_double
instead of directly with ‘*’:
inline double access_double (double *unaligned_ptr) { union d2i { double d; int i[2]; }; union d2i *p = (union d2i *) unaligned_ptr; union d2i u; u.i[0] = p->i[0]; u.i[1] = p->i[1]; return u.d; }
Storing into the pointer can be done likewise with the same union.
malloc
function in the ‘libmalloc.a’ library
may allocate memory that is only 4 byte aligned. Since GNU CC on the
Sparc assumes that doubles are 8 byte aligned, this may result in a
fatal signal if doubles are stored in memory allocated by the
‘libmalloc.a’ library.
The solution is to not use the ‘libmalloc.a’ library. Use instead
malloc
and related functions from ‘libc.a’; they do not have
this problem.
_dlclose
, _dlsym
or _dlopen
when linking, compile and link against the file
‘mit/util/misc/dlsym.c’ from the MIT version of X windows.
cc
does not
compile GNU CC correctly. We do not yet know why. However, GNU CC
compiled on earlier HP-UX versions works properly on HP-UX 9.01 and can
compile itself properly on 9.01.
alloca
or variable-size arrays. This is because GNU CC doesn’t
generate HP-UX unwind descriptors for such functions. It may even be
impossible to generate them.
(warning) Use of GR3 when frame >= 8192 may cause conflict.
These warnings are harmless and can be safely ignored.
IBM has produced a fixed version of the assembler. The upgraded assembler unfortunately was not included in any of the AIX 3.2 update PTF releases (3.2.2, 3.2.3, or 3.2.3e). Users of AIX 3.1 should request PTF U403044 from IBM and users of AIX 3.2 should request PTF U416277. See the file ‘README.RS6000’ for more details on these updates.
You can test for the presense of a fixed assembler by using the command
as -u < /dev/null
If the command exits normally, the assembler fix already is installed. If the assembler complains that "-u" is an unknown flag, you need to order the fix.
extern int foo; … foo … static int foo;
will cause the linker to report an undefined symbol foo
.
Although this behavior differs from most other systems, it is not a
bug because redefining an extern
variable as static
is undefined in ANSI C.
size_t
. You should change ‘sys/types.h’ by adding these
lines around the definition of size_t
:
#ifndef _SIZE_T #define _SIZE_T actual typedef here #endif
GNU CC uses the same convention as the Ultrix C compiler. You can use these options to produce code compatible with the Fortran compiler:
-fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
-L/usr/local/lib/gcc-lib/we32k-att-sysv/2.7.0 -lgcc -lc_s
The first specifies where to find the library ‘libgcc.a’ specified with the ‘-lgcc’ option.
GNU CC does linking by invoking ld
, just as cc
does, and
there is no reason why it should matter which compilation program
you use to invoke ld
. If someone tracks this problem down,
it can probably be fixed easily.
ecvt
, fcvt
and gcvt
. Given valid
floating point numbers, they sometimes print ‘NaN’.
Or use the ‘-noasmopt’ option when you compile GNU CC with itself, and then again when you compile your program. (This is a temporary kludge to turn off assembler optimization on Irix.) If this proves to be what you need, edit the assembler spec in the file ‘specs’ so that it unconditionally passes ‘-O0’ to the assembler, and never passes ‘-O2’ or ‘-O3’.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Certain programs have problems compiling.
#ifdef __STDC__ #define NeedFunctionPrototypes 0 #endif
-traditional -Dvolatile=__volatile__ -I/usr/include/sun -I/usr/ucbinclude -fpcc-struct-return
most of which are unnecessary with GCC 2.4.5 and newer versions. You
can make a properly working Perl by setting ccflags
to
‘-fwritable-strings’ (implied by the ‘-traditional’ in the
original options) and cppflags
to empty in ‘config.sh’, then
typing ‘./doSH; make depend; make’.
You can prevent this problem by linking GNU CC with the GNU malloc (which thus replaces the malloc that comes with the system). GNU malloc is available as a separate package, and also in the file ‘src/gmalloc.c’ in the GNU Emacs 19 distribution.
If you have installed GNU malloc as a separate library package, use this option when you relink GNU CC:
MALLOC=/usr/local/lib/libgmalloc.a
Alternatively, if you have compiled ‘gmalloc.c’ from Emacs 19, copy the object file to ‘gmalloc.o’ and use this option when you relink GNU CC:
MALLOC=gmalloc.o
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
There are several noteworthy incompatibilities between GNU C and most existing (non-ANSI) versions of C. The ‘-traditional’ option eliminates many of these incompatibilities, but not all, by telling GNU C to behave like the other C compilers.
One consequence is that you cannot call mktemp
with a string
constant argument. The function mktemp
always alters the
string its argument points to.
Another consequence is that sscanf
does not work on some systems
when passed a string constant as its format control string or input.
This is because sscanf
incorrectly tries to write into the string
constant. Likewise fscanf
and scanf
.
The best solution to these problems is to change the program to use
char
-array variables with initialization strings for these
purposes instead of string constants. But if this is not possible,
you can use the ‘-fwritable-strings’ flag, which directs GNU CC
to handle string constants the same way most C compilers do.
‘-traditional’ also has this effect, among others.
-2147483648
is positive.
This is because 2147483648 cannot fit in the type int
, so
(following the ANSI C rules) its data type is unsigned long int
.
Negating this value yields 2147483648 again.
#define foo(a) "a"
will produce output "a"
regardless of what the argument a is.
The ‘-traditional’ option directs GNU CC to handle such cases (among others) in the old-fashioned (non-ANSI) fashion.
setjmp
and longjmp
, the only automatic
variables guaranteed to remain valid are those declared
volatile
. This is a consequence of automatic register
allocation. Consider this function:
jmp_buf j;
foo ()
{
int a, b;
a = fun1 ();
if (setjmp (j))
return a;
a = fun2 ();
/* longjmp (j)
may occur in fun3
. */
return a + fun3 ();
}
Here a
may or may not be restored to its first value when the
longjmp
occurs. If a
is allocated in a register, then
its first value is restored; otherwise, it keeps the last value stored
in it.
If you use the ‘-W’ option with the ‘-O’ option, you will get a warning when GNU CC thinks such a problem might be possible.
The ‘-traditional’ option directs GNU C to put variables in
the stack by default, rather than in registers, in functions that
call setjmp
. This results in the behavior found in
traditional C compilers.
foobar ( #define luser hack)
ANSI C does not permit such a construct. It would make sense to support it when ‘-traditional’ is used, but it is too much work to implement.
In some other C compilers, a extern
declaration affects all the
rest of the file even if it happens within a block.
The ‘-traditional’ option directs GNU C to treat all extern
declarations as global, like traditional compilers.
long
, etc., with a typedef name,
as shown here:
typedef int foo; typedef long foo bar;
In ANSI C, this is not allowed: long
and other type modifiers
require an explicit int
. Because this criterion is expressed
by Bison grammar rules rather than C code, the ‘-traditional’
flag cannot alter it.
#if 0 You can't expect this to work. #endif
The best solution to such a problem is to put the text into an actual C comment delimited by ‘/*…*/’. However, ‘-traditional’ suppresses these error messages.
time
, so it did not matter what type your program declared it to
return. But in systems with ANSI C headers, time
is declared to
return time_t
, and if that is not the same as long
, then
‘long time ();’ is erroneous.
The solution is to change your program to use time_t
as the return
type of time
.
float
, PCC converts it to
a double. GNU CC actually returns a float
. If you are concerned
with PCC compatibility, you should declare your functions to return
double
; you might as well say what you mean.
The method used by GNU CC is as follows: a structure or union which is
1, 2, 4 or 8 bytes long is returned like a scalar. A structure or union
with any other size is stored into an address supplied by the caller
(usually in a special, fixed register, but on some machines it is passed
on the stack). The machine-description macros STRUCT_VALUE
and
STRUCT_INCOMING_VALUE
tell GNU CC where to pass this address.
By contrast, PCC on most target machines returns structures and unions of any size by copying the data into an area of static storage, and then returning the address of that storage as if it were a pointer value. The caller must copy the data from that memory area to the place where the value is wanted. GNU CC does not use this method because it is slower and nonreentrant.
On some newer machines, PCC uses a reentrant convention for all structure and union returning. GNU CC on most of these machines uses a compatible convention when returning structures and unions in memory, but still returns small structures and unions in registers.
You can tell GNU CC to use a compatible convention for all structure and union returning with the option ‘-fpcc-struct-return’.
A preprocessing token is a preprocessing number if it begins with a digit and is followed by letters, underscores, digits, periods and ‘e+’, ‘e-’, ‘E+’, or ‘E-’ character sequences.
To make the above program fragment valid, place whitespace in front of the minus sign. This whitespace will end the preprocessing number.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU CC needs to install corrected versions of some system header files. This is because most target systems have some header files that won’t work with GNU CC unless they are changed. Some have bugs, some are incompatible with ANSI C, and some depend on special features of other compilers.
Installing GNU CC automatically creates and installs the fixed header
files, by running a program called fixincludes
(or for certain
targets an alternative such as fixinc.svr4
). Normally, you
don’t need to pay attention to this. But there are cases where it
doesn’t do the right thing automatically.
The programs that fix the header files do not understand this special way of using symbolic links; therefore, the directory of fixed header files is good only for the machine model used to build it.
In SunOS 4, only programs that look inside the kernel will notice the difference between machine models. Therefore, for most purposes, you need not be concerned about this.
It is possible to make separate sets of fixed header files for the different machine models, and arrange a structure of symbolic links so as to use the proper set, but you’ll have to do this by hand.
fixincludes
script to fail.
This means you will encounter problems due to bugs in the system header files. It may be no comfort that they aren’t GNU CC’s fault, but it does mean that there’s nothing for us to do about them.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU CC by itself attempts to be what the ISO/ANSI C standard calls a conforming freestanding implementation. This means all ANSI C language features are available, as well as the contents of ‘float.h’, ‘limits.h’, ‘stdarg.h’, and ‘stddef.h’. The rest of the C library is supplied by the vendor of the operating system. If that C library doesn’t conform to the C standards, then your programs might get warnings (especially when using ‘-Wall’) that you don’t expect.
For example, the sprintf
function on SunOS 4.1.3 returns
char *
while the C standard says that sprintf
returns an
int
. The fixincludes
program could make the prototype for
this function match the Standard, but that would be wrong, since the
function will still return char *
.
If you need a Standard compliant library, then you need to find one, as
GNU CC does not provide one. The GNU C library (called glibc
)
has been ported to a number of operating systems, and provides ANSI/ISO,
POSIX, BSD and SystemV compatibility. You could also ask your operating
system vendor if newer libraries are available.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These problems are perhaps regrettable, but we don’t know any practical way around them.
This occurs because sometimes GNU CC optimizes the variable out of existence. There is no way to tell the debugger how to compute the value such a variable “would have had”, and it is not clear that would be desirable anyway. So GNU CC simply does not mention the eliminated variable when it writes debugging information.
You have to expect a certain amount of disagreement between the executable and your source code, when you use optimization.
int foo (struct mumble *); struct mumble { … }; int foo (struct mumble *x) { … }
This code really is erroneous, because the scope of struct
mumble
in the prototype is limited to the argument list containing it.
It does not refer to the struct mumble
defined with file scope
immediately below—they are two unrelated types with similar names in
different scopes.
But in the definition of foo
, the file-scope type is used
because that is available to be inherited. Thus, the definition and
the prototype do not match, and you get an error.
This behavior may seem silly, but it’s what the ANSI standard specifies.
It is easy enough for you to make your code work by moving the
definition of struct mumble
above the prototype. It’s not worth
being incompatible with ANSI C just to avoid an error for the example
shown above.
If you care about controlling the amount of memory that is accessed, use volatile but do not use bitfields.
If new system header files are installed, nothing automatically arranges
to update the corrected header files. You will have to reinstall GNU CC
to fix the new header files. More specifically, go to the build
directory and delete the files ‘stmp-fixinc’ and
‘stmp-headers’, and the subdirectory include
; then do
‘make install’ again.
double
in memory.
Compiled code moves values between memory and floating point registers
at its convenience, and moving them into memory truncates them.
You can partially avoid this problem by using the ‘-ffloat-store’ option (@pxref{Optimize Options}).
If the code is rewritten to use the ANSI standard ‘stdarg.h’ method of variable arguments, and the prototype is in scope at the time of the call, everything will work fine.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
C++ is a complex language and an evolving one, and its standard definition (the ANSI C++ draft standard) is also evolving. As a result, your C++ compiler may occasionally surprise you, even when its behavior is correct. This section discusses some areas that frequently give rise to questions of this sort.
4.10.1 Declare and Define Static Members | Static member declarations are not definitions | |
4.10.2 Temporaries May Vanish Before You Expect | Temporaries may vanish before you expect |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When a class has static data members, it is not enough to declare the static member; you must also define it. For example:
class Foo { … void method(); static int bar; };
This declaration only establishes that the class Foo
has an
int
named Foo::bar
, and a member function named
Foo::method
. But you still need to define both
method
and bar
elsewhere. According to the draft ANSI
standard, you must supply an initializer in one (and only one) source
file, such as:
int Foo::bar = 0;
Other C++ compilers may not correctly implement the standard behavior.
As a result, when you switch to g++
from one of these compilers,
you may discover that a program that appeared to work correctly in fact
does not conform to the standard: g++
reports as undefined
symbols any static data members that lack definitions.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
It is dangerous to use pointers or references to portions of a
temporary object. The compiler may very well delete the object before
you expect it to, leaving a pointer to garbage. The most common place
where this problem crops up is in classes like the libg++
String
class, that define a conversion function to type
char *
or const char *
. However, any class that returns
a pointer to some internal structure is potentially subject to this
problem.
For example, a program may use a function strfunc
that returns
String
objects, and another function charfunc
that
operates on pointers to char
:
String strfunc (); void charfunc (const char *);
In this situation, it may seem natural to write ‘charfunc (strfunc ());’ based on the knowledge that class String
has an
explicit conversion to char
pointers. However, what really
happens is akin to ‘charfunc (strfunc ().convert ());’,
where the convert
method is a function to do the same data
conversion normally performed by a cast. Since the last use of the
temporary String
object is the call to the conversion function,
the compiler may delete that object before actually calling
charfunc
. The compiler has no way of knowing that deleting the
String
object will invalidate the pointer. The pointer then
points to garbage, so that by the time charfunc
is called, it
gets an invalid argument.
Code like this may run successfully under some other compilers, especially those that delete temporaries relatively late. However, the GNU C++ behavior is also standard-conformant, so if your program depends on late destruction of temporaries it is not portable.
If you think this is surprising, you should be aware that the ANSI C++ committee continues to debate the lifetime-of-temporaries problem.
For now, at least, the safe way to write such code is to give the temporary a name, which forces it to remain until the end of the scope of the name. For example:
String& tmp = strfunc (); charfunc (tmp);
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
protoize
The conversion programs protoize
and unprotoize
can
sometimes change a source file in a way that won’t work unless you
rearrange it.
protoize
can insert references to a type name or type tag before
the definition, or in a file where they are not defined.
If this happens, compiler error messages should show you where the new references are, so fixing the file by hand is straightforward.
protoize
cannot figure out.
For example, it can’t determine argument types for declaring a
pointer-to-function variable; this you must do by hand. protoize
inserts a comment containing ‘???’ each time it finds such a
variable; so you can find all such variables by searching for this
string. ANSI C does not require declaring the argument types of
pointer-to-function types.
unprotoize
can easily introduce bugs. If the program
relied on prototypes to bring about conversion of arguments, these
conversions will not take place in the program without prototypes.
One case in which you can be sure unprotoize
is safe is when
you are removing prototypes that were made with protoize
; if
the program worked before without any prototypes, it will work again
without them.
You can find all the places where this problem might occur by compiling the program with the ‘-Wconversion’ option. It prints a warning whenever an argument is converted.
protoize
cannot get the argument types for a function whose
definition was not actually compiled due to preprocessing conditionals.
When this happens, protoize
changes nothing in regard to such
a function. protoize
tries to detect such instances and warn
about them.
You can generally work around this problem by using protoize
step
by step, each time specifying a different set of ‘-D’ options for
compilation, until all of the functions have been converted. There is
no automatic way to verify that you have got them all, however.
If you plan on converting source files which contain such code, it is recommended that you first make sure that each conditionally compiled region of source code which contains an alternative function header also contains at least one additional follower token (past the final right parenthesis of the function header). This should circumvent the problem.
unprotoize
can become confused when trying to convert a function
definition or declaration which contains a declaration for a
pointer-to-function formal argument which has the same name as the
function being defined or declared. We recommand you avoid such choices
of formal parameter names.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section lists changes that people frequently request, but which we do not make because we think GNU CC is better without them.
Such a feature would work only occasionally—only for calls that appear in the same file as the called function, following the definition. The only way to check all calls reliably is to add a prototype for the function. But adding a prototype eliminates the motivation for this feature. So the feature is not worthwhile.
Shift count operands are probably signed more often than unsigned. Warning about this would cause far more annoyance than good.
Such assignments must be very common; warning about them would cause more annoyance than good.
It’s very common to have unreachable code in machine-generated programs. For example, this happens normally in some files of GNU C itself.
Coming as I do from a Lisp background, I balk at the idea that there is
something dangerous about discarding a value. There are functions that
return values which some callers may find useful; it makes no sense to
clutter the program with a cast to void
whenever the value isn’t
useful.
This assumption is false on certain systems when ‘#pragma weak’ is used.
This would cause storage layout to be incompatible with most other C compilers. And it doesn’t seem very important, given that you can get the same result in other ways. The case where it matters most is when the enumeration-valued object is inside a structure, and in that case you can specify a field width explicitly.
The ANSI C standard leaves it up to the implementation whether a bitfield
declared plain int
is signed or not. This in effect creates two
alternative dialects of C.
The GNU C compiler supports both dialects; you can specify the signed dialect with ‘-fsigned-bitfields’ and the unsigned dialect with ‘-funsigned-bitfields’. However, this leaves open the question of which dialect to use by default.
Currently, the preferred dialect makes plain bitfields signed, because
this is simplest. Since int
is the same as signed int
in
every other context, it is cleanest for them to be the same in bitfields
as well.
Some computer manufacturers have published Application Binary Interface standards which specify that plain bitfields should be unsigned. It is a mistake, however, to say anything about this issue in an ABI. This is because the handling of plain bitfields distinguishes two dialects of C. Both dialects are meaningful on every type of machine. Whether a particular object file was compiled using signed bitfields or unsigned is of no concern to other object files, even if they access the same bitfields in the same data structures.
A given program is written in one or the other of these two dialects. The program stands a chance to work on most any machine if it is compiled with the proper dialect. It is unlikely to work at all if compiled with the wrong dialect.
Many users appreciate the GNU C compiler because it provides an environment that is uniform across machines. These users would be inconvenienced if the compiler treated plain bitfields differently on certain machines.
Occasionally users write programs intended only for a particular machine type. On these occasions, the users would benefit if the GNU C compiler were to support by default the same dialect as the other compilers on that machine. But such applications are rare. And users writing a program to run on more than one type of machine cannot possibly benefit from this kind of compatibility.
This is why GNU CC does and will treat plain bitfields in the same fashion on all types of machines (by default).
There are some arguments for making bitfields unsigned by default on all machines. If, for example, this becomes a universal de facto standard, it would make sense for GNU CC to go along with it. This is something to be considered in the future.
(Of course, users strongly concerned about portability should indicate explicitly in each bitfield whether it is signed or not. In this way, they write programs which have the same meaning in both C dialects.)
__STDC__
when ‘-ansi’ is not used.
Currently, GNU CC defines __STDC__
as long as you don’t use
‘-traditional’. This provides good results in practice.
Programmers normally use conditionals on __STDC__
to ask whether
it is safe to use certain features of ANSI C, such as function
prototypes or ANSI token concatenation. Since plain ‘gcc’ supports
all the features of ANSI C, the correct answer to these questions is
“yes”.
Some users try to use __STDC__
to check for the availability of
certain library facilities. This is actually incorrect usage in an ANSI
C program, because the ANSI C standard says that a conforming
freestanding implementation should define __STDC__
even though it
does not have the library facilities. ‘gcc -ansi -pedantic’ is a
conforming freestanding implementation, and it is therefore required to
define __STDC__
, even though it does not come with an ANSI C
library.
Sometimes people say that defining __STDC__
in a compiler that
does not completely conform to the ANSI C standard somehow violates the
standard. This is illogical. The standard is a standard for compilers
that claim to support ANSI C, such as ‘gcc -ansi’—not for other
compilers such as plain ‘gcc’. Whatever the ANSI C standard says
is relevant to the design of plain ‘gcc’ without ‘-ansi’ only
for pragmatic reasons, not as a requirement.
__STDC__
in C++.
Programs written to compile with C++-to-C translators get the
value of __STDC__
that goes with the C compiler that is
subsequently used. These programs must test __STDC__
to determine what kind of C preprocessor that compiler uses:
whether they should concatenate tokens in the ANSI C fashion
or in the traditional fashion.
These programs work properly with GNU C++ if __STDC__
is defined.
They would not work otherwise.
In addition, many header files are written to provide prototypes in ANSI
C but not in traditional C. Many of these header files can work without
change in C++ provided __STDC__
is defined. If __STDC__
is not defined, they will all fail, and will all need to be changed to
test explicitly for C++ as well.
GNU CC does not delete “empty” loops because the most likely reason you would put one in a program is to have a delay. Deleting them will not make real programs run any faster, so it would be pointless.
It would be different if optimization of a nonempty loop could produce an empty one. But this generally can’t happen.
It is never safe to depend on the order of evaluation of side effects. For example, a function call like this may very well behave differently from one compiler to another:
void func (int, int); int i = 2; func (i++, i++);
There is no guarantee (in either the C or the C++ standard language
definitions) that the increments will be evaluated in any particular
order. Either increment might happen first. func
might get the
arguments ‘2, 3’, or it might get ‘3, 2’, or even ‘2, 2’.
Strictly speaking, there is no prohibition in the ANSI C standard against allowing structures with volatile fields in registers, but it does not seem to make any sense and is probably not what you wanted to do. So the compiler will give an error message in this case.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The GNU compiler can produce two kinds of diagnostics: errors and warnings. Each kind has a different purpose:
Warnings may indicate danger points where you should check to make sure that your program really does what you intend; or the use of obsolete features; or the use of nonstandard features of GNU C or C++. Many warnings are issued only if you ask for them, with one of the ‘-W’ options (for instance, ‘-Wall’ requests a variety of useful warnings).
GNU CC always tries to compile your program if possible; it never gratuitously rejects a program whose meaning is clear merely because (for instance) it fails to conform to a standard. In some cases, however, the C and C++ standards specify that certain extensions are forbidden, and a diagnostic must be issued by a conforming compiler. The ‘-pedantic’ option tells GNU CC to issue warnings in such cases; ‘-pedantic-errors’ says to make them errors instead. This does not mean that all non-ANSI constructs get warnings or errors.
@xref{Warning Options,,Options to Request or Suppress Warnings}, for more detail on these and related command-line options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Your bug reports play an essential role in making GNU CC reliable.
When you encounter a problem, the first thing to do is to see if it is already known. See section Known Causes of Trouble with GNU CC. If it isn’t known, then you should report the problem.
Reporting a bug may help you by bringing a solution to your problem, or it may not. (If it does not, look in the service directory; see How To Get Help with GNU CC.) In any case, the principal function of a bug report is to help the entire community by making the next version of GNU CC work better. Bug reports are your contribution to the maintenance of GNU CC.
Since the maintainers are very overloaded, we cannot respond to every bug report. However, if the bug has not been fixed, we are likely to send you a patch and ask you to tell us whether it works.
In order for a bug report to serve its purpose, you must include the information that makes for fixing the bug.
5.1 Have You Found a Bug? | Have you really found a bug? | |
5.2 Where to Report Bugs | Where to send your bug report. | |
5.3 How to Report Bugs | How to report a bug effectively. | |
5.4 Sending Patches for GNU CC | How to send a patch for GNU CC. | |
4 Known Causes of Trouble with GNU CC | Known problems. | |
6 How To Get Help with GNU CC | Where to ask for help. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you are not sure whether you have found a bug, here are some guidelines:
asm
statement), that is a compiler bug, unless the
compiler reports errors (not just warnings) which would ordinarily
prevent the assembler from being run.
However, you must double-check to make sure, because you may have run into an incompatibility between GNU C and traditional C (see section Incompatibilities of GNU CC). These incompatibilities might be considered bugs, but they are inescapable consequences of valuable features.
Or you may have a program whose behavior is undefined, which happened by chance to give the desired results with another C or C++ compiler.
For example, in many nonoptimizing compilers, you can write ‘x;’
at the end of a function instead of ‘return x;’, with the same
results. But the value of the function is undefined if return
is omitted; it is not a bug when GNU CC produces different results.
Problems often result from expressions with two increment operators,
as in f (*p++, *p++)
. Your previous compiler might have
interpreted that expression the way you intended; GNU CC might
interpret it another way. Neither compiler is wrong. The bug is
in your code.
After you have localized the error to a single source line, it should be easy to check for these things. If your program is correct and well defined, you have found a compiler bug.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Send bug reports for GNU C to ‘bug-gcc@prep.ai.mit.edu’.
Send bug reports for GNU C++ to ‘bug-g++@prep.ai.mit.edu’. If your bug involves the C++ class library libg++, send mail to ‘bug-lib-g++@prep.ai.mit.edu’. If you’re not sure, you can send the bug report to both lists.
Do not send bug reports to ‘help-gcc@prep.ai.mit.edu’ or to the newsgroup ‘gnu.gcc.help’. Most users of GNU CC do not want to receive bug reports. Those that do, have asked to be on ‘bug-gcc’ and/or ‘bug-g++’.
The mailing lists ‘bug-gcc’ and ‘bug-g++’ both have newsgroups which serve as repeaters: ‘gnu.gcc.bug’ and ‘gnu.g++.bug’. Each mailing list and its newsgroup carry exactly the same messages.
Often people think of posting bug reports to the newsgroup instead of mailing them. This appears to work, but it has one problem which can be crucial: a newsgroup posting does not contain a mail path back to the sender. Thus, if maintainers need more information, they may be unable to reach you. For this reason, you should always send bug reports by mail to the proper mailing list.
As a last resort, send bug reports on paper to:
GNU Compiler Bugs Free Software Foundation 675 Mass Ave Cambridge, MA 02139
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The fundamental principle of reporting bugs usefully is this: report all the facts. If you are not sure whether to state a fact or leave it out, state it!
Often people omit facts because they think they know what causes the problem and they conclude that some details don’t matter. Thus, you might assume that the name of the variable you use in an example does not matter. Well, probably it doesn’t, but one cannot be sure. Perhaps the bug is a stray memory reference which happens to fetch from the location where that name is stored in memory; perhaps, if the name were different, the contents of that location would fool the compiler into doing the right thing despite the bug. Play it safe and give a specific, complete example. That is the easiest thing for you to do, and the most helpful.
Keep in mind that the purpose of a bug report is to enable someone to fix the bug if it is not known. It isn’t very important what happens if the bug is already known. Therefore, always write your bug reports on the assumption that the bug is not known.
Sometimes people give a few sketchy facts and ask, “Does this ring a bell?” This cannot help us fix a bug, so it is basically useless. We respond by asking for enough details to enable us to investigate. You might as well expedite matters by sending them to begin with.
Try to make your bug report self-contained. If we have to ask you for more information, it is best if you include all the previous information in your response, as well as the information that was missing.
Please report each bug in a separate message. This makes it easier for us to track which bugs have been fixed and to forward your bugs reports to the appropriate maintainer.
Do not compress and encode any part of your bug report using programs such as ‘uuencode’. If you do so it will slow down the processing of your bug. If you must submit multiple large files, use ‘shar’, which allows us to read your message without having to run any decompression programs.
To enable someone to investigate the bug, you should include all these things:
Without this, we won’t know whether there is any point in looking for the bug in the current version of GNU CC.
A single statement is not enough of an example. In order to compile it, it must be embedded in a complete file of compiler input; and the bug might depend on the details of how this is done.
Without a real example one can compile, all anyone can do about your bug report is wish you luck. It would be futile to try to guess how to provoke the bug. For example, bugs in register allocation and reloading frequently depend on every little detail of the function they happen in.
Even if the input file that fails comes from a GNU program, you should still send the complete test case. Don’t ask the GNU CC maintainers to do the extra work of obtaining the program in question—they are all overworked as it is. Also, the problem may depend on what is in the header files on your system; it is unreliable for the GNU CC maintainers to try the problem with the header files available to them. By sending CPP output, you can eliminate this source of uncertainty and save us a certain percentage of wild goose chases.
If we were to try to guess the arguments, we would probably guess wrong and then we would not encounter the bug.
configure
command when you installed
the compiler.
Be precise about these changes. A description in English is not enough—send a context diff for them.
Adding files of your own (such as a machine description for a machine we don’t support) is a modification of the compiler source.
Of course, if the bug is that the compiler gets a fatal signal, then one can’t miss it. But if the bug is incorrect output, the maintainer might not notice unless it is glaringly wrong. None of us has time to study all the assembler code from a 50-line C program just on the chance that one instruction might be wrong. We need you to do this part!
Even if the problem you experience is a fatal signal, you should still say so explicitly. Suppose something strange is going on, such as, your copy of the compiler is out of synch, or you have encountered a bug in the C library on your system. (This has happened!) Your copy might crash and the copy here would not. If you said to expect a crash, then when the compiler here fails to crash, we would know that the bug was not happening. If you don’t say to expect a crash, then we would not know whether the bug was happening. We would not be able to draw any conclusion from our observations.
If the problem is a diagnostic when compiling GNU CC with some other compiler, say whether it is a warning or an error.
Often the observed symptom is incorrect output when your program is run. Sad to say, this is not enough information unless the program is short and simple. None of us has time to study a large program to figure out how it would work if compiled correctly, much less which line of it was compiled wrong. So you will have to do that. Tell us which source line it is, and what incorrect result happens when that line is executed. A person who understands the program can find this as easily as finding a bug in the program itself.
The line numbers in the development sources don’t match those in your sources. Your line numbers would convey no useful information to the maintainers.
For example, many people send just a backtrace, but that is never useful by itself. A simple backtrace with arguments conveys little about GNU CC because the compiler is largely data-driven; the same functions are called over and over for different RTL insns, doing different things depending on the details of the insn.
Most of the arguments listed in the backtrace are useless because they are pointers to RTL list structure. The numeric values of the pointers, which the debugger prints in the backtrace, have no significance whatever; all that matters is the contents of the objects they point to (and most of the contents are other such pointers).
In addition, most compiler passes consist of one or more loops that scan the RTL insn sequence. The most vital piece of information about such a loop—which insn it has reached—is usually in a local variable, not in an argument.
What you need to provide in addition to a backtrace are the values of
the local variables for several stack frames up. When a local
variable or an argument is an RTX, first print its value and then use
the GDB command pr
to print the RTL expression that it points
to. (If GDB doesn’t run on your machine, use your debugger to call
the function debug_rtx
with the RTX as an argument.) In
general, whenever a variable is a pointer, its value is no use
without the data it points to.
Here are some things that are not necessary:
Often people who encounter a bug spend a lot of time investigating which changes to the input file will make the bug go away and which changes will not affect it.
This is often time consuming and not very useful, because the way we will find the bug is by running a single example under the debugger with breakpoints, not by pure deduction from a series of examples. You might as well save your time for something else.
Of course, if you can find a simpler example to report instead of the original one, that is a convenience. Errors in the output will be easier to spot, running under the debugger will take less time, etc. Most GNU CC bugs involve just one function, so the most straightforward way to simplify an example is to delete all the function definitions except the one where the bug occurs. Those earlier in the file may be replaced by external declarations if the crucial function depends on them. (Exception: inline functions may affect compilation of functions defined later in the file.)
However, simplification is not vital; if you don’t want to do this, report the bug anyway and send the entire test case you used.
A patch for the bug is useful if it is a good one. But don’t omit the necessary information, such as the test case, on the assumption that a patch is all we need. We might see problems with your patch and decide to fix the problem another way, or we might not understand it at all.
Sometimes with a program as complicated as GNU CC it is very hard to construct an example that will make the program follow a certain path through the code. If you don’t send the example, we won’t be able to construct one, so we won’t be able to verify that the bug is fixed.
And if we can’t understand what bug you are trying to fix, or why your patch should be an improvement, we won’t install it. A test case will help us to understand.
See section Sending Patches for GNU CC, for guidelines on how to make it easy for us to understand and install your patches.
Such guesses are usually wrong. Even I can’t guess right about such things without first using the debugger to find the facts.
We have no way of examining a core dump for your type of machine unless we have an identical system—and if we do have one, we should be able to reproduce the crash ourselves.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you would like to write bug fixes or improvements for the GNU C
compiler, that is very helpful. Send suggested fixes to the bug report
mailing list, bug-gcc@prep.ai.mit.edu
.
Please follow these guidelines so we can study your patches efficiently. If you don’t follow these guidelines, your information might still be useful, but using it will take extra work. Maintaining GNU C is a lot of work in the best of circumstances, and we can’t keep up unless you do your best to help.
(Referring to a bug report is not as good as including it, because then we will have to look it up, and we have probably already deleted it if we’ve already fixed the bug.)
If you make two changes for separate reasons, then we might not want to install them both. We might want to install just one. If you send them all jumbled together in a single set of diffs, we have to do extra work to disentangle them—to figure out which parts of the change serve which purpose. If we don’t have time for this, we might have to ignore your changes entirely.
If you send each change as soon as you have written it, with its own explanation, then the two changes never get tangled up, and we can consider each one properly without any extra work to disentangle them.
Ideally, each change you send should be impossible to subdivide into parts that we might want to consider separately, because each of its parts gets its motivation from the other parts.
Since you should send each change separately, you might as well send it right away. That gives us the option of installing it immediately if it is important.
If you have GNU diff, use ‘diff -cp’, which shows the name of the function that each change occurs in.
Read the ‘ChangeLog’ file to see what sorts of information to put in, and to learn the style that we use. The purpose of the change log is to show people where to find what was changed. So you need to be specific about what functions you changed; in large functions, it’s often helpful to indicate where within the function the change was.
On the other hand, once you have shown people where to find the change, you need not explain its purpose. Thus, if you add a new function, all you need to say about it is that it is new. If you feel that the purpose needs explaining, it probably does—but the explanation will be much more useful if you put it in comments in the code.
If you would like your name to appear in the header line for who made the change, send us the header line.
People often suggest fixing a problem by changing machine-independent files such as ‘toplev.c’ to do something special that a particular system needs. Sometimes it is totally obvious that such changes would break GNU CC for almost all users. We can’t possibly make a change like that. At best it might tell us how to write another patch that would solve the problem acceptably.
Sometimes people send fixes that might be an improvement in general—but it is hard to be sure of this. It’s hard to install such changes because we have to study them very carefully. Of course, a good explanation of the reasoning by which you concluded the change was correct can help convince us.
The safest changes are changes to the configuration files for a particular machine. These are safe because they can’t create new bugs on other machines.
Please help us keep up with the workload by designing the patch in a form that is good to install.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you need help installing, using or changing GNU CC, there are two ways to find it:
bug-gcc@prep.ai.mit.edu
, and if that brings no response, try
help-gcc@prep.ai.mit.edu
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is how to use GNU CC on VMS.
7.1 Include Files and VMS | Where the preprocessor looks for the include files. | |
7.2 Global Declarations and VMS | How to do globaldef, globalref and globalvalue with GNU CC. | |
7.3 Other VMS Issues | Misc information. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Due to the differences between the filesystems of Unix and VMS, GNU CC attempts to translate file names in ‘#include’ into names that VMS will understand. The basic strategy is to prepend a prefix to the specification of the include file, convert the whole filename to a VMS filename, and then try to open the file. GNU CC tries various prefixes one by one until one of them succeeds:
Conversion works like this: the first directory name becomes a device, and the rest of the directories are converted into VMS-format directory names. For example, the name ‘X11/foobar.h’ is translated to ‘X11:[000000]foobar.h’ or ‘X11:foobar.h’, whichever one can be opened. This strategy allows you to assign a logical name to point to the actual location of the header files.
Include directives of the form:
#include foobar
are a common source of incompatibility between VAX-C and GNU CC. VAX-C
treats this much like a standard #include <foobar.h>
directive.
That is incompatible with the ANSI C behavior implemented by GNU CC: to
expand the name foobar
as a macro. Macro expansion should
eventually yield one of the two standard formats for #include
:
#include "file" #include <file>
If you have this problem, the best solution is to modify the source to
convert the #include
directives to one of the two standard forms.
That will work with either compiler. If you want a quick and dirty fix,
define the file names as macros with the proper expansion, like this:
#define stdio <stdio.h>
This will work, as long as the name doesn’t conflict with anything else in the program.
Another source of incompatibility is that VAX-C assumes that:
#include "foobar"
is actually asking for the file ‘foobar.h’. GNU CC does not make this assumption, and instead takes what you ask for literally; it tries to read the file ‘foobar’. The best way to avoid this problem is to always specify the desired file extension in your include directives.
GNU CC for VMS is distributed with a set of include files that is
sufficient to compile most general purpose programs. Even though the
GNU CC distribution does not contain header files to define constants
and structures for some VMS system-specific functions, there is no
reason why you cannot use GNU CC with any of these functions. You first
may have to generate or create header files, either by using the public
domain utility UNSDL
(which can be found on a DECUS tape), or by
extracting the relevant modules from one of the system macro libraries,
and using an editor to construct a C header file.
A #include
file name cannot contain a DECNET node name. The
preprocessor reports an I/O error if you attempt to use a node name,
whether explicitly, or implicitly via a logical name.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU CC does not provide the globalref
, globaldef
and
globalvalue
keywords of VAX-C. You can get the same effect with
an obscure feature of GAS, the GNU assembler. (This requires GAS
version 1.39 or later.) The following macros allow you to use this
feature in a fairly natural way:
#ifdef __GNUC__ #define GLOBALREF(TYPE,NAME) \ TYPE NAME \ asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME) #define GLOBALDEF(TYPE,NAME,VALUE) \ TYPE NAME \ asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME) \ = VALUE #define GLOBALVALUEREF(TYPE,NAME) \ const TYPE NAME[1] \ asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME) #define GLOBALVALUEDEF(TYPE,NAME,VALUE) \ const TYPE NAME[1] \ asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME) \ = {VALUE} #else #define GLOBALREF(TYPE,NAME) \ globalref TYPE NAME #define GLOBALDEF(TYPE,NAME,VALUE) \ globaldef TYPE NAME = VALUE #define GLOBALVALUEDEF(TYPE,NAME,VALUE) \ globalvalue TYPE NAME = VALUE #define GLOBALVALUEREF(TYPE,NAME) \ globalvalue TYPE NAME #endif
(The _$$PsectAttributes_GLOBALSYMBOL
prefix at the start of the
name is removed by the assembler, after it has modified the attributes
of the symbol). These macros are provided in the VMS binaries
distribution in a header file ‘GNU_HACKS.H’. An example of the
usage is:
GLOBALREF (int, ijk); GLOBALDEF (int, jkl, 0);
The macros GLOBALREF
and GLOBALDEF
cannot be used
straightforwardly for arrays, since there is no way to insert the array
dimension into the declaration at the right place. However, you can
declare an array with these macros if you first define a typedef for the
array type, like this:
typedef int intvector[10]; GLOBALREF (intvector, foo);
Array and structure initializers will also break the macros; you can
define the initializer to be a macro of its own, or you can expand the
GLOBALDEF
macro by hand. You may find a case where you wish to
use the GLOBALDEF
macro with a large array, but you are not
interested in explicitly initializing each element of the array. In
such cases you can use an initializer like: {0,}
, which will
initialize the entire array to 0
.
A shortcoming of this implementation is that a variable declared with
GLOBALVALUEREF
or GLOBALVALUEDEF
is always an array. For
example, the declaration:
GLOBALVALUEREF(int, ijk);
declares the variable ijk
as an array of type int [1]
.
This is done because a globalvalue is actually a constant; its “value”
is what the linker would normally consider an address. That is not how
an integer value works in C, but it is how an array works. So treating
the symbol as an array name gives consistent results—with the
exception that the value seems to have the wrong type. Don’t
try to access an element of the array. It doesn’t have any elements.
The array “address” may not be the address of actual storage.
The fact that the symbol is an array may lead to warnings where the variable is used. Insert type casts to avoid the warnings. Here is an example; it takes advantage of the ANSI C feature allowing macros that expand to use the same name as the macro itself.
GLOBALVALUEREF (int, ss$_normal); GLOBALVALUEDEF (int, xyzzy,123); #ifdef __GNUC__ #define ss$_normal ((int) ss$_normal) #define xyzzy ((int) xyzzy) #endif
Don’t use globaldef
or globalref
with a variable whose
type is an enumeration type; this is not implemented. Instead, make the
variable an integer, and use a globalvaluedef
for each of the
enumeration values. An example of this would be:
#ifdef __GNUC__ GLOBALDEF (int, color, 0); GLOBALVALUEDEF (int, RED, 0); GLOBALVALUEDEF (int, BLUE, 1); GLOBALVALUEDEF (int, GREEN, 3); #else enum globaldef color {RED, BLUE, GREEN = 3}; #endif
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU CC automatically arranges for main
to return 1 by default if
you fail to specify an explicit return value. This will be interpreted
by VMS as a status code indicating a normal successful completion.
Version 1 of GNU CC did not provide this default.
GNU CC on VMS works only with the GNU assembler, GAS. You need version 1.37 or later of GAS in order to produce value debugging information for the VMS debugger. Use the ordinary VMS linker with the object files produced by GAS.
Under previous versions of GNU CC, the generated code would occasionally give strange results when linked to the sharable ‘VAXCRTL’ library. Now this should work.
A caveat for use of const
global variables: the const
modifier must be specified in every external declaration of the variable
in all of the source files that use that variable. Otherwise the linker
will issue warnings about conflicting attributes for the variable. Your
program will still work despite the warnings, but the variable will be
placed in writable storage.
Although the VMS linker does distinguish between upper and lower case letters in global symbols, most VMS compilers convert all such symbols into upper case and most run-time library routines also have upper case names. To be able to reliably call such routines, GNU CC (by means of the assembler GAS) converts global symbols into upper case like other VMS compilers. However, since the usual practice in C is to distinguish case, GNU CC (via GAS) tries to preserve usual C behavior by augmenting each name that is not all lower case. This means truncating the name to at most 23 characters and then adding more characters at the end which encode the case pattern of those 23. Names which contain at least one dollar sign are an exception; they are converted directly into upper case without augmentation.
Name augmentation yields bad results for programs that use precompiled libraries (such as Xlib) which were generated by another compiler. You can use the compiler option ‘/NOCASE_HACK’ to inhibit augmentation; it makes external C functions and variables case-independent as is usual on VMS. Alternatively, you could write all references to the functions and variables in such libraries using lower case; this will work on VMS, but is not portable to other systems. The compiler option ‘/NAMES’ also provides control over global name handling.
Function and variable names are handled somewhat differently with GNU C++. The GNU C++ compiler performs name mangling on function names, which means that it adds information to the function name to describe the data types of the arguments that the function takes. One result of this is that the name of a function can become very long. Since the VMS linker only recognizes the first 31 characters in a name, special action is taken to ensure that each function and variable has a unique name that can be represented in 31 characters.
If the name (plus a name augmentation, if required) is less than 32 characters in length, then no special action is performed. If the name is longer than 31 characters, the assembler (GAS) will generate a hash string based upon the function name, truncate the function name to 23 characters, and append the hash string to the truncated name. If the ‘/VERBOSE’ compiler option is used, the assembler will print both the full and truncated names of each symbol that is truncated.
The ‘/NOCASE_HACK’ compiler option should not be used when you are
compiling programs that use libg++. libg++ has several instances of
objects (i.e. Filebuf
and filebuf
) which become
indistinguishable in a case-insensitive environment. This leads to
cases where you need to inhibit augmentation selectively (if you were
using libg++ and Xlib in the same program, for example). There is no
special feature for doing this, but you can get the result by defining a
macro for each mixed case symbol for which you wish to inhibit
augmentation. The macro should expand into the lower case equivalent of
itself. For example:
#define StuDlyCapS studlycaps
These macro definitions can be placed in a header file to minimize the number of changes to your source code.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The main goal of GNU CC was to make a good, fast compiler for machines in the class that the GNU system aims to run on: 32-bit machines that address 8-bit bytes and have several general registers. Elegance, theoretical power and simplicity are only secondary.
GNU CC gets most of the information about the target machine from a machine description which gives an algebraic formula for each of the machine’s instructions. This is a very clean way to describe the target. But when the compiler needs information that is difficult to express in this fashion, I have not hesitated to define an ad-hoc parameter to the machine description. The purpose of portability is to reduce the total work needed on the compiler; it was not of interest for its own sake.
GNU CC does not contain machine dependent code, but it does contain code
that depends on machine parameters such as endianness (whether the most
significant byte has the highest or lowest address of the bytes in a word)
and the availability of autoincrement addressing. In the RTL-generation
pass, it is often necessary to have multiple strategies for generating code
for a particular kind of syntax tree, strategies that are usable for different
combinations of parameters. Often I have not tried to address all possible
cases, but only the common ones or only the ones that I have encountered.
As a result, a new target may require additional strategies. You will know
if this happens because the compiler will call abort
. Fortunately,
the new strategies can be added in a machine-independent fashion, and will
affect only the target machines that need them.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU CC is normally configured to use the same function calling convention normally in use on the target system. This is done with the machine-description macros described (@pxref{Target Macros}).
However, returning of structure and union values is done differently on some target machines. As a result, functions compiled with PCC returning such types cannot be called from code compiled with GNU CC, and vice versa. This does not cause trouble often because few Unix library routines return structures or unions.
GNU CC code returns structures and unions that are 1, 2, 4 or 8 bytes
long in the same registers used for int
or double
return
values. (GNU CC typically allocates variables of such types in
registers also.) Structures and unions of other sizes are returned by
storing them into an address passed by the caller (usually in a
register). The machine-description macros STRUCT_VALUE
and
STRUCT_INCOMING_VALUE
tell GNU CC where to pass this address.
By contrast, PCC on most target machines returns structures and unions of any size by copying the data into an area of static storage, and then returning the address of that storage as if it were a pointer value. The caller must copy the data from that memory area to the place where the value is wanted. This is slower than the method used by GNU CC, and fails to be reentrant.
On some target machines, such as RISC machines and the 80386, the standard system convention is to pass to the subroutine the address of where to return the value. On these machines, GNU CC has been configured to be compatible with the standard compiler, when this method is used. It may not be compatible for structures of 1, 2, 4 or 8 bytes.
GNU CC uses the system’s standard convention for passing arguments. On some machines, the first few arguments are passed in registers; in others, all are passed on the stack. It would be possible to use registers for argument passing on any machine, and this would probably result in a significant speedup. But the result would be complete incompatibility with code that follows the standard convention. So this change is practical only if you are switching to GNU CC as the sole C compiler for the system. We may implement register argument passing on certain machines once we have a complete GNU system so that we can compile the libraries with GNU CC.
On some machines (particularly the Sparc), certain types of arguments are passed “by invisible reference”. This means that the value is stored in memory, and the address of the memory location is passed to the subroutine.
If you use longjmp
, beware of automatic variables. ANSI C says that
automatic variables that are not declared volatile
have undefined
values after a longjmp
. And this is all GNU CC promises to do,
because it is very difficult to restore register variables correctly, and
one of GNU CC’s features is that it can put variables in registers without
your asking it to.
If you want a variable to be unaltered by longjmp
, and you don’t
want to write volatile
because old C compilers don’t accept it,
just take the address of the variable. If a variable’s address is ever
taken, even if just to compute it and ignore it, then the variable cannot
go in a register:
{ int careful; &careful; … }
Code compiled with GNU CC may call certain library routines. Most of
them handle arithmetic for which there are no instructions. This
includes multiply and divide on some machines, and floating point
operations on any machine for which floating point support is disabled
with ‘-msoft-float’. Some standard parts of the C library, such as
bcopy
or memcpy
, are also called automatically. The usual
function call interface is used for calling the library routines.
These library routines should be defined in the library ‘libgcc.a’, which GNU CC automatically searches whenever it links a program. On machines that have multiply and divide instructions, if hardware floating point is in use, normally ‘libgcc.a’ is not needed, but it is searched just in case.
Each arithmetic function is defined in ‘libgcc1.c’ to use the corresponding C arithmetic operator. As long as the file is compiled with another C compiler, which supports all the C arithmetic operators, this file will work portably. However, ‘libgcc1.c’ does not work if compiled with GNU CC, because each arithmetic function would compile into a call to itself!
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The overall control structure of the compiler is in ‘toplev.c’. This file is responsible for initialization, decoding arguments, opening and closing files, and sequencing the passes.
The parsing pass is invoked only once, to parse the entire input. The RTL intermediate code for a function is generated as the function is parsed, a statement at a time. Each statement is read in as a syntax tree and then converted to RTL; then the storage for the tree for the statement is reclaimed. Storage for types (and the expressions for their sizes), declarations, and a representation of the binding contours and how they nest, remain until the function is finished being compiled; these are all needed to output the debugging information.
Each time the parsing pass reads a complete function definition or
top-level declaration, it calls either the function
rest_of_compilation
, or the function
rest_of_decl_compilation
in ‘toplev.c’, which are
responsible for all further processing necessary, ending with output of
the assembler language. All other compiler passes run, in sequence,
within rest_of_compilation
. When that function returns from
compiling a function definition, the storage used for that function
definition’s compilation is entirely freed, unless it is an inline
function
(@pxref{Inline,,An Inline Function is As Fast As a Macro}).
Here is a list of all the passes of the compiler and their source files. Also included is a description of where debugging dumps can be requested with ‘-d’ options.
The tree representation does not entirely follow C syntax, because it is intended to support other languages as well.
Language-specific data type analysis is also done in this pass, and every tree node that represents an expression has a data type attached. Variables are represented as declaration nodes.
Constant folding and some arithmetic simplifications are also done during this pass.
The language-independent source files for parsing are ‘stor-layout.c’, ‘fold-const.c’, and ‘tree.c’. There are also header files ‘tree.h’ and ‘tree.def’ which define the format of the tree representation.
The source files to parse C are ‘c-parse.in’, ‘c-decl.c’, ‘c-typeck.c’, ‘c-aux-info.c’, ‘c-convert.c’, and ‘c-lang.c’ along with header files ‘c-lex.h’, and ‘c-tree.h’.
The source files for parsing C++ are ‘cp-parse.y’,
‘cp-class.c’,
‘cp-cvt.c’, ‘cp-decl.c’, ‘cp-decl2.c’,
‘cp-dem.c’, ‘cp-except.c’,
‘cp-expr.c’, ‘cp-init.c’, ‘cp-lex.c’,
‘cp-method.c’, ‘cp-ptree.c’,
‘cp-search.c’, ‘cp-tree.c’, ‘cp-type2.c’, and
‘cp-typeck.c’, along with header files ‘cp-tree.def’,
‘cp-tree.h’, and ‘cp-decl.h’.
The special source files for parsing Objective C are ‘objc-parse.y’, ‘objc-actions.c’, ‘objc-tree.def’, and ‘objc-actions.h’. Certain C-specific files are used for this as well.
The file ‘c-common.c’ is also used for all of the above languages.
This is where the bulk of target-parameter-dependent code is found, since often it is necessary for strategies to apply only when certain standard kinds of instructions are available. The purpose of named instruction patterns is to provide this information to the RTL generation pass.
Optimization is done in this pass for if
-conditions that are
comparisons, boolean operations or conditional expressions. Tail
recursion is detected at this time also. Decisions are made about how
best to arrange loops and how to output switch
statements.
The source files for RTL generation include
‘stmt.c’,
‘calls.c’,
‘expr.c’,
‘explow.c’,
‘expmed.c’,
‘function.c’,
‘optabs.c’
and ‘emit-rtl.c’.
Also, the file
‘insn-emit.c’, generated from the machine description by the
program genemit
, is used in this pass. The header file
‘expr.h’ is used for communication within this pass.
The header files ‘insn-flags.h’ and ‘insn-codes.h’,
generated from the machine description by the programs genflags
and gencodes
, tell this pass which standard names are available
for use and which patterns correspond to them.
Aside from debugging information output, none of the following passes refers to the tree structure representation of the function (only part of which is saved).
The decision of whether the function can and should be expanded inline in its subsequent callers is made at the end of rtl generation. The function must meet certain criteria, currently related to the size of the function and the types and number of parameters it has. Note that this function may contain loops, recursive calls to itself (tail-recursive functions can be inlined!), gotos, in short, all constructs supported by GNU CC. The file ‘integrate.c’ contains the code to save a function’s rtl for later inlining and to inline that rtl when the function is called. The header file ‘integrate.h’ is also used for this purpose.
The option ‘-dr’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.rtl’ to the input file name.
Jump optimization is performed two or three times. The first time is immediately following RTL generation. The second time is after CSE, but only if CSE says repeated jump optimization is needed. The last time is right before the final pass. That time, cross-jumping and deletion of no-op move instructions are done together with the optimizations described above.
The source file of this pass is ‘jump.c’.
The option ‘-dj’ causes a debugging dump of the RTL code after this pass is run for the first time. This dump file’s name is made by appending ‘.jump’ to the input file name.
The option ‘-ds’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.cse’ to the input file name.
The option ‘-dL’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.loop’ to the input file name.
The option ‘-dt’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.cse2’ to the input file name.
This pass also deletes computations whose results are never used, and combines memory references with add or subtract instructions to make autoincrement or autodecrement addressing.
The option ‘-df’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.flow’ to the input file name. If stupid register allocation is in use, this dump file reflects the full results of such allocation.
The option ‘-dc’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.combine’ to the input file name.
Instruction scheduling is performed twice. The first time is immediately after instruction combination and the second is immediately after reload.
The option ‘-dS’ causes a debugging dump of the RTL code after this pass is run for the first time. The dump file’s name is made by appending ‘.sched’ to the input file name.
The option ‘-dl’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.lreg’ to the input file name.
The reload pass also optionally eliminates the frame pointer and inserts instructions to save and restore call-clobbered registers around calls.
Source files are ‘reload.c’ and ‘reload1.c’, plus the header ‘reload.h’ used for communication between them.
The option ‘-dg’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.greg’ to the input file name.
The option ‘-dR’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.sched2’ to the input file name.
The option ‘-dJ’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.jump2’ to the input file name.
The option ‘-dd’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.dbr’ to the input file name.
The options ‘-dk’ causes a debugging dump of the RTL code after this pass. This dump file’s name is made by appending ‘.stack’ to the input file name.
The source files are ‘final.c’ plus ‘insn-output.c’; the latter is generated automatically from the machine description by the tool ‘genoutput’. The header file ‘conditions.h’ is used for communication between these files.
Some additional files are used by all or many passes:
gen*
also use these files to read and work with the machine
description RTL.
genconfig
.
HARD_REG_SET
, a bit-vector
with a bit for each hard register, and some macros to manipulate it.
This type is just int
if the machine has few enough hard registers;
otherwise it is an array of int
and some of the macros expand
into loops.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The configuration file ‘xm-machine.h’ contains macro definitions that describe the machine and system on which the compiler is running, unlike the definitions in ‘machine.h’, which describe the machine for which the compiler is producing output. Most of the values in ‘xm-machine.h’ are actually the same on all machines that GNU CC runs on, so large parts of all configuration files are identical. But there are some macros that vary:
USG
Define this macro if the host system is System V.
VMS
Define this macro if the host system is VMS.
FATAL_EXIT_CODE
A C expression for the status code to be returned when the compiler exits after serious errors.
SUCCESS_EXIT_CODE
A C expression for the status code to be returned when the compiler exits without serious errors.
HOST_WORDS_BIG_ENDIAN
Defined if the host machine stores words of multi-word values in big-endian order. (GNU CC does not depend on the host byte ordering within a word.)
HOST_FLOAT_WORDS_BIG_ENDIAN
Define this macro to be 1 if the host machine stores DFmode
,
XFmode
or TFmode
floating point numbers in memory with the
word containing the sign bit at the lowest address; otherwise, define it
to be zero.
This macro need not be defined if the ordering is the same as for multi-word integers.
HOST_FLOAT_FORMAT
A numeric code distinguishing the floating point format for the host
machine. See TARGET_FLOAT_FORMAT
in @ref{Storage Layout} for the
alternatives and default.
HOST_BITS_PER_CHAR
A C expression for the number of bits in char
on the host
machine.
HOST_BITS_PER_SHORT
A C expression for the number of bits in short
on the host
machine.
HOST_BITS_PER_INT
A C expression for the number of bits in int
on the host
machine.
HOST_BITS_PER_LONG
A C expression for the number of bits in long
on the host
machine.
ONLY_INT_FIELDS
Define this macro to indicate that the host compiler only supports
int
bit fields, rather than other integral types, including
enum
, as do most C compilers.
OBSTACK_CHUNK_SIZE
A C expression for the size of ordinary obstack chunks. If you don’t define this, a usually-reasonable default is used.
OBSTACK_CHUNK_ALLOC
The function used to allocate obstack chunks.
If you don’t define this, xmalloc
is used.
OBSTACK_CHUNK_FREE
The function used to free obstack chunks.
If you don’t define this, free
is used.
USE_C_ALLOCA
Define this macro to indicate that the compiler is running with the
alloca
implemented in C. This version of alloca
can be
found in the file ‘alloca.c’; to use it, you must also alter the
‘Makefile’ variable ALLOCA
. (This is done automatically
for the systems on which we know it is needed.)
If you do define this macro, you should probably do it as follows:
#ifndef __GNUC__ #define USE_C_ALLOCA #else #define alloca __builtin_alloca #endif
so that when the compiler is compiled with GNU CC it uses the more
efficient built-in alloca
function.
FUNCTION_CONVERSION_BUG
Define this macro to indicate that the host compiler does not properly handle converting a function value to a pointer-to-function when it is used in an expression.
HAVE_VPRINTF
Define this if the library function vprintf
is available on your
system.
MULTIBYTE_CHARS
Define this macro to enable support for multibyte characters in the input to GNU CC. This requires that the host system support the ANSI C library functions for converting multibyte characters to wide characters.
HAVE_PUTENV
Define this if the library function putenv
is available on your
system.
POSIX
Define this if your system is POSIX.1 compliant.
NO_SYS_SIGLIST
Define this if your system does not provide the variable
sys_siglist
.
DONT_DECLARE_SYS_SIGLIST
Define this if your system has the variable sys_siglist
, and
there is already a declaration of it in the system header files.
USE_PROTOTYPES
Define this to be 1 if you know that the host compiler supports prototypes, even if it doesn’t define __STDC__, or define it to be 0 if you do not want any prototypes used in compiling GNU CC. If ‘USE_PROTOTYPES’ is not defined, it will be determined automatically whether your compiler supports prototypes by checking if ‘__STDC__’ is defined.
NO_MD_PROTOTYPES
Define this if you wish suppression of prototypes generated from the machine description file, but to use other prototypes within GNU CC. If ‘USE_PROTOTYPES’ is defined to be 0, or the host compiler does not support prototypes, this macro has no effect.
MD_CALL_PROTOTYPES
Define this if you wish to generate prototypes for the
gen_call
or gen_call_value
functions generated from
the machine description file. If ‘USE_PROTOTYPES’ is
defined to be 0, or the host compiler does not support
prototypes, or ‘NO_MD_PROTOTYPES’ is defined, this macro has
no effect. As soon as all of the machine descriptions are
modified to have the appropriate number of arguments, this macro
will be removed.
Some systems do provide this variable, but with a different name such
as _sys_siglist
. On these systems, you can define
sys_siglist
as a macro which expands into the name actually
provided.
NO_STAB_H
Define this if your system does not have the include file ‘stab.h’. If ‘USG’ is defined, ‘NO_STAB_H’ is assumed.
PATH_SEPARATOR
Define this macro to be a C character constant representing the character used to separate components in paths. The default value is. the colon character
DIR_SEPARATOR
If your system uses some character other than slash to separate directory names within a file specification, define this macro to be a C character constant specifying that character. When GNU CC displays file names, the character you specify will be used. GNU CC will test for both slash and the character you specify when parsing filenames.
OBJECT_SUFFIX
Define this macro to be a C string representing the suffix for object files on your machine. If you do not define this macro, GNU CC will use ‘.o’ as the suffix for object files.
EXECUTABLE_SUFFIX
Define this macro to be a C string representing the suffix for executable files on your machine. If you do not define this macro, GNU CC will use the null string as the suffix for object files.
COLLECT_EXPORT_LIST
If defined, collect2
will scan the individual object files
specified on its command line and create an export list for the linker.
Define this macro for systems like AIX, where the linker discards
object files that are not referenced from main
and uses export
lists.
In addition, configuration files for system V define bcopy
,
bzero
and bcmp
as aliases. Some files define alloca
as a macro when compiled with GNU CC, in order to take advantage of the
benefit of GNU CC’s built-in alloca
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | '
A B C D E F G H I J K L M N O P R S T U V W X |
---|
Jump to: | '
A B C D E F G H I J K L M N O P R S T U V W X |
---|
[Top] | [Contents] | [Index] | [ ? ] |
protoize
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February 12, 2023 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on February 12, 2023 using texi2html 5.0.